from flask import Blueprint, jsonify, request
from apps.task.business.citask import CiTaskBusiness

ciTask = Blueprint('ciTask', __name__)


@ciTask.route('/run', methods=['POST'])
def task():
    """
        @api {get} /v1/ci/task/run jenkins调用接口用例
        @apiName RunTask
        @apiGroup CI
        @apiDescription jenkins调用接口用例
        @apiSuccessExample {json} Success-Response:
        HTTP/1.1 200 OK
        {
            "code": 0,
            "data": [
                {
                    "msg": "",
                    "status": 0
                    "data": {}
                }
            "message": "ok"
        }
        """
    aladdin_project_id = request.json['aladdin_project_id']
    build_number = request.json['build_number']
    job_name = request.json['job_name']
    git_url = request.json['git_url']
    git_branch = request.json['git_branch']
    git_author_name = request.json['git_author_name']
    git_commit = request.json['git_commit']
    params = {"interface_project_id": aladdin_project_id, "git_url": git_url, "git_branch": git_branch, "ci": 1}
    response = CiTaskBusiness.run_task(params)
    return jsonify(response)
